import 'package:flutter/material.dart';
import 'package:flutter2/common/values/values.dart';
import 'package:flutter2/common/widgets/input.dart';
import 'package:flutter2/common/widgets/toast.dart';

import '../../common/widgets/widgets.dart';

class SignUpPage extends StatefulWidget {
  const SignUpPage({super.key});

  @override
  State<SignUpPage> createState() => _SignUpPageState();
}

class _SignUpPageState extends State<SignUpPage> {
  final TextEditingController nameController = TextEditingController();
  final TextEditingController emailController = TextEditingController();
  final TextEditingController pwdController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      appBar: AppBar(
        title: Text(''),
        backgroundColor: Colors.transparent,
        elevation: 0,
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            color: AppColors.primaryText,
          ),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        actions: [
          IconButton(
            onPressed: () {
              toast(msg: '承诺不泄漏用户信息.');
            },
            icon: Icon(
              Icons.info_outline,
              color: AppColors.primaryText,
            ),
          )
        ],
      ),
      body: Center(
        child: Column(
          children: [
            Divider(height: 1),
            buildLogo(),
            buildForm(),
            Spacer(),
            buildThirdPartyLogin(),
            buildHaveAccountButton(),
          ],
        ),
      ),
    );
  }

  Widget buildLogo() {
    return Container(
      margin: EdgeInsets.only(top: 50),
      child: Text(
        '用户注册',
        textAlign: TextAlign.center,
        style: TextStyle(
            color: AppColors.primaryText,
            fontFamily: 'Montserrat',
            fontWeight: FontWeight.w600,
            fontSize: 24,
            height: 1),
      ),
    );
  }

  Widget buildForm() {
    return Container(
      width: 295,
      margin: EdgeInsets.only(top: 49),
      child: Column(
        children: [
          inputTextEdit(
            controller: nameController,
            hintText: '姓名',
            marginTop: 0,
          ),
          inputTextEdit(
            controller: emailController,
            hintText: '邮箱',
          ),
          inputTextEdit(
            controller: pwdController,
            hintText: '密码',
            isPwd: true,
          ),
          Container(
            height: 44,
            margin: EdgeInsets.only(top: 15),
            child: buttonWidget(
                title: '创建',
                onPressed: () {
                  if (nameController.value.text.isEmpty) {
                    toast(msg: '姓名不能为空！');
                  } else if (!RegExp(
                          "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\$")
                      .hasMatch(emailController.value.text)) {
                    toast(msg: '邮箱格式不正确！');
                  } else if (pwdController.value.text.length < 6) {
                    toast(msg: '密码不能少于6位！');
                  } else {
                    Navigator.pop(context);
                  }
                }),
          ),
          Container(
            height: 36,
            margin: EdgeInsets.only(top: 10),
            child: TextButton(
              onPressed: () {
                toast(msg: '怎么办呀，怎么办？');
              },
              child: Text(
                '忘记密码?',
                textAlign: TextAlign.center,
                style: TextStyle(
                  fontFamily: 'Avenir',
                  fontSize: 16,
                  height: 1,
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget buildThirdPartyLogin() {
    return Container();
  }

  Widget buildHaveAccountButton() {
    return Container();
  }
}
